<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <script>
    //  浅拷贝
    var obj = {
      name: "小赵",
      age: 88,
      hobby: {
        chi: ["烧烤", "火锅"],
        he: ["啤酒", "白酒"],
        nv: {
          mei: ["刘亦菲", "高圆圆"],
          chou: ["凤姐", "如花"]
        }
      }
    }
    // 浅拷贝 只复制对象的第一层属性
    function simpleClone(obj) {
      var result = {};
      for (var i in obj) {
        result[i] = obj[i];
      }
      return result;
    }
    var newobj = simpleClone(obj)
    console.log(newobj)
    newobj.name = "小孙"
    newobj.hobby.he[0] = "红酒"
    console.log(obj.name)
    console.log(obj.hobby.he[0])

    // 深拷贝的方式1  JSON.parse(JSON.stringify(对象))
    var myobj = JSON.parse(JSON.stringify(obj))
    console.log(myobj)
    //2 递归函数的深拷贝
    function deepClone(obj) {
      var o = obj instanceof Array ? [] : {};
      for (var k in obj) {
        o[k] = typeof obj[k] === "object" ? arguments.callee(obj[k]) : obj[k];
      }
      return o;
    }
    var cloneObj = deepClone(obj)
    console.log(cloneObj)

  </script>

</body>

</html>